def binary_search(sorted_array, val) -> int:
    if not sorted_array:
        return -1
    beg = 0
    end = len(sorted_array) - 1
    while beg < end:
        mid = (beg+end)//2
        if sorted_array[mid] >= val:
            end=mid
        else:
            beg=mid+1
    
    return beg


nums= [17, 20, 26, 31, 31, 31, 55, 77, 93]

ans=binary_search(nums,31)
print(ans)